package model.dominio;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.OneToMany;
import javax.persistence.PostPersist;
import javax.persistence.PostUpdate;
import javax.persistence.Table;
import model.dao.DaoBase;

@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@Table(name = "Cliente")
public class Cliente extends Pessoa implements Serializable {

    /**
     * 
     * @element-type Locacao
     */
    @OneToMany(mappedBy = "cliente")
    private List<Locacao> locacoes = new ArrayList<Locacao>();

    public Cliente() {
    }

    /**
     * @return the locacoes
     */
    public List<Locacao> getLocacoes() {
        return locacoes;
    }

    public Cliente(String nome, String cpf) {
        super(nome, cpf);
    }

    public Cliente(String nome, String cpf, String telefone, String endereco) {
        super(nome, cpf, telefone, endereco);
    }

    @Override
    public String toString() {
        return super.toString();
    }

    @PostPersist
    public void gerarLogCad() {
        Logg logg = new Logg();
        logg.setCodigo_objeto(super.getCodigo());
        logg.setAcao(new AcaoSistema(6));
        logg.setData_hora(super.getData_ultima_alteracao());
        logg.setUsuario(super.getUsuario());
        new DaoBase().salvar(logg);
    }

    @PostUpdate
    public void gerarLogAlt() {
        Logg logg = new Logg();
        logg.setCodigo_objeto(this.getCodigo());
        logg.setAcao(new AcaoSistema(7));
        logg.setData_hora(this.getData_ultima_alteracao());
        logg.setUsuario(this.getUsuario());
        new DaoBase().salvar(logg);
    }
}